<?php /* Copyright 2010 Karl R. Wilcox 

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License. */

// mullet

$charge = array (

  'patterns' => array (
  'm(o|u)ll?ets?',
  ),
  'modifiers' => array (
    array ( NULL, '(pierced|voided)', 'mod', 'pierced',    ),
    array ( 5, '(of|de) # ?points', 'mod', 'points',    ),
  ),

  'doc' => 'Stuff...',

);

if ( $node == null ) {
  $charge['height'] = 400;
  $charge['width'] = 400;
  $charge['body'] = '<g><path d="M200,0L258.778525,119.098301 390.211303,138.196601 295.105652,230.901699 317.557050,361.803399 200.000000,300.000000 82.442950,361.803399 104.894348,230.901699 9.788697,138.196601 141.221475,119.098301 Z" /></g>';
} else {
  $n = get_mod ( $node, 'points' );
  if ( $n < 1 or $n > 20 ) $n = 5;
  $pierced = get_mod ( $node, 'pierced' );
  $void_col = null; // TODO Fix void colour for mullet
  $r1 = 100;        // Inner radius
  $r2 = 200;        // Outer radius
  $alpha = 360 / $n; // Angle between points

  $charge['height'] = 400;
  $charge['width'] = 400;
  // $retval['title'] = 'Mullet';
  // $retval['desc'] = 'Autogenerated mullet of ' . $n . ' points.';
  // Leave wflex and hflex unset - we do not want any scaling
  $body = '<g><path d="M200,0';
  $beta = deg2rad($alpha / 2);
  $body .= sprintf( "L%4f,%4f ", 200 +  ($r1 * sin ( $beta )), 200 - ($r1 * cos ( $beta )));

  for ( $i = 2; $i <= $n; $i++ ) {
    $beta = deg2rad(($alpha / 2) + ( $alpha * ($i - 1)));
    $body .= sprintf( "%4f,%4f ", 200 + ($r2 * sin( deg2rad($alpha * ($i - 1))) ), 200 - ( $r2 * cos( deg2rad ($alpha * ($i - 1)) )));
    $body .= sprintf( "%4f,%4f ", 200 +  ($r1 * sin ( $beta )), 200 - ($r1 * cos ( $beta )));
  }
  $body .= 'Z';
  if ( $pierced ) { // need an empty hole...
    $body .= ' M160,200 a40,40 0,0,0 80,0 a40,40 0,0,0 -80,0z';
  }
  $body .= '" />';
  if ( $void_col != null ) {
    $body .= apply_tincture ( $void_col, '<cicrle x="200" y="200" r="40" />' );
  }
  $body .= '</g>';
  $charge['body'] = $body;
}

?>
